package com.qsl.hook;

import com.qsl.hook.utils.ProcessUtil;
import com.sun.jna.Platform;
import oshi.SystemInfo;
import oshi.software.os.OSProcess;
import oshi.software.os.OperatingSystem;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * mainClass
 * @author 青石路
 */
public class HookMain {

    public static void main(String[] args) throws Exception {
        // processTest();
        long l = 1737098287793L;
        System.out.println(l);
    }

    public static void processTest() throws IOException, InterruptedException {
        String command = "";
        if (Platform.isWindows()) {
            command = "ping -n 10 localhost";
        } else if (Platform.isLinux() || Platform.isAIX()) {
            command = "ping -c 10 localhost";
        }
        Process process = Runtime.getRuntime().exec(command);
        int processId = ProcessUtil.getProcessId(process);
        System.out.println("ping 进程id = " + processId);
        OSProcess processInfo = ProcessUtil.getProcessInfo(processId);
        System.out.println("进程启动时间：" + processInfo.getStartTime());
        new Thread(() -> {
            try (BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream(), System.getProperty("sun.jnu.encoding")))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).start();
        // 等待命令执行完成
        int i = process.waitFor();
        if (i == 0) {
            System.out.println("进程执行完毕");
        } else {
            System.out.println("进程执行失败");
        }
    }
}
